import {
  DashboardOutlined,
  BulbOutlined,
  SettingOutlined,
  TagsOutlined,
  FolderOpenOutlined,
  EditOutlined,
  CoffeeOutlined,
  CommentOutlined,
  OrderedListOutlined,
} from '@ant-design/icons-vue'

import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

import Layout from '@/layout/index.vue'
import DashboardPage from '@/pages/dashboard/index.vue'
import AnnouncementPage from '@/pages/announcement/index.vue'
import CategoryPage from '@/pages/category/index.vue'
import TagPage from '@/pages/tag/index.vue'
import CommentPage from '@/pages/comment/index.vue'
import ProfilePage from '@/pages/profile/index.vue'
import ArticleListPage from '@/pages/article/List/index.vue'
import ArticlePostPage from '@/pages/article/post.vue'
import LoginPage from '@/pages/login/index.vue'

export const childrenRoutes: Array<RouteRecordRaw> = [
  {
    path: '/dashboard',
    name: 'dashboard',
    component: DashboardPage,
    meta: {
      title: '超级看板',
      icon: DashboardOutlined,
    },
  },
  {
    path: '/announcement',
    name: 'announcement',
    component: AnnouncementPage,
    meta: {
      title: '公告管理',
      icon: BulbOutlined,
    },
  },
  {
    path: '/category',
    name: 'category',
    component: CategoryPage,
    meta: {
      title: '文章分类',
      icon: FolderOpenOutlined,
    },
  },
  {
    path: '/tag',
    name: 'tag',
    component: TagPage,
    meta: {
      title: '文章标签',
      icon: TagsOutlined,
    },
  },
  {
    path: '/article',
    name: 'article',
    redirect: '/article/list',
    meta: {
      title: '文章管理',
      icon: CoffeeOutlined,
    },
    children: [
      {
        path: '/article/list',
        name: 'list',
        component: ArticleListPage,
        meta: {
          title: '文章列表',
          icon: OrderedListOutlined,
        },
      },
      {
        path: '/article/post',
        name: 'post',
        component: ArticlePostPage,
        meta: {
          title: '新撰文章',
          icon: EditOutlined,
        },
      },
      {
        path: '/article/edit/:article_id',
        name: 'edit',
        props: (to: { params: { article_id: string } }) => ({
          articleId: String(to.params.article_id),
        }),
        component: () => import('@/pages/article/Edit/index.vue'),
        meta: {
          title: '编辑文章',
          icon: EditOutlined,
        },
      },
    ],
  },
  {
    path: '/comment',
    name: 'comment',
    component: CommentPage,
    meta: {
      title: '评论管理',
      icon: CommentOutlined,
    },
  },
  {
    path: '/profile',
    name: 'profile',
    component: ProfilePage,
    meta: {
      title: '系统设置',
      icon: SettingOutlined,
    },
  },
]

export const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'layout',
    redirect: '/dashboard',
    component: Layout,
    meta: {
      title: '首页',
    },
    children: [...childrenRoutes],
  },
  {
    path: '/login',
    name: 'login',
    component: LoginPage,
    meta: {
      title: '登录',
    },
  },
]

export default createRouter({
  history: createWebHistory('/'),
  routes,
  strict: true,
  scrollBehavior: () => ({ left: 0, top: 0 }),
})
